FROM nginx:1.16-alpine

ARG X_GID
ARG X_UID

RUN set -eux; \
    if [ -z "`getent group ${X_GID}`" ]; then \
        addgroup --system --gid ${X_GID} clonetrooper; \
    fi; \
    adduser --system --disabled-password -S --uid ${X_UID} -G clonetrooper clonetrooper 

COPY ./conf.d/ /etc/nginx/conf.d/
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./secrets/id_rsa /run/secrets/dx/deploy
COPY  --from=php-yjs-pay-test:latest --chown=clonetrooper:clonetrooper /data/www/pay/ /data/www/pay/
COPY --chown=clonetrooper:clonetrooper ./assets /data/www/pay/backend/web/assets

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
	&& apk update \
    && apk add -U tzdata \
    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && apk add openssh-client git mysql-client \
    && apk del tzdata \
    && rm -rf /var/cache/apk/* \
    && rm -rf /root/.cache \
    && rm -rf /tmp/* \
    && chmod 0600 /run/secrets/dx/deploy \
    && mkdir -p -m 0700 /root/.ssh 

RUN { \
        echo 'Host dx.wangcaigu.cn'; \
        echo '    Hostname dx.wangcaigu.cn'; \
        echo '    IdentityFile /run/secrets/dx/deploy'; \
        echo '    IPQoS throughput'; \
    } | tee /etc/ssh/ssh_config 

WORKDIR /data/www/pay

EXPOSE 80
